<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="./css/clock.css">
    <style>
        
        /* main.css */
        * {
            padding: 0;
            margin: 0;
            transition: all .5s;
        }
        main {
            position: absolute;
            width: 100vw;
            height: 100vh;
            background: center center url(./img/day.jpg) no-repeat #E2FBF5;
            background-size: contain;
        }
        main.night {
            background-image: url(./img/night.jpg);
            background-color: #7A81B7;
        }

        /* test */
        button.aaa {
            position: fixed;
            right: 100px;
            top: 100px;
            width: 50px;
            height: 50px;
        }
        button.bbb {
            position: fixed;
            right: 100px;
            top: 200px;
            width: 50px;
            height: 50px;
        }
        #reminder {
            position: fixed;
            bottom: 0;
            height: 500px;
            width: 200px;
            display: flex;
            flex-wrap: wrap;
            left: -50vw;
        }
        #reminder .img {
            background: url("./img/22222.png") right center no-repeat;
            background-size: contain;
            height: 300px;
            width: 150px;
            transform: rotateY(180deg)
        }
        #reminder .text {
            position: absolute;
            top: -30px;
            left: 30px;
            background: #fffa;
            width: 100%;
            padding: 10px;
            box-sizing: border-box;
            border-radius: 15px;
            border: solid #fff;
        }
        #reminder .text::before {
            content: "";
            display: block;
            position: absolute;
            bottom: -30px;
            left: 20px;
            border-left: solid 15px #0000;
            border-top: solid 15px #fff;
            border-right: solid 15px #0000;
            border-bottom: solid 15px #0000;
        }
    </style>
</head>
<body>
    <main>
        <div id="ClockComponents">
            <div class="calendars">
                <div class="week"></div>
                <div class="month"></div>
                <div class="day"></div>
            </div>
            <div class="clock">
                <div class="hour">23</div>
                <span>:</span>
                <div class="minutes">33</div>
            </div>
            <div id="message"></div>
        </div>
        <!-- <button class="aaa" onclick="document.querySelector('main').classList.add('night');document.querySelector('#ClockComponents').className='night'">🌙</button>
        <button class="bbb" onclick="document.querySelector('main').classList.remove('night');document.querySelector('#ClockComponents').className=''">☀</button> -->
        <div id="reminder">
            <div class="text">别摸鱼啦!(#｀-_ゝ-) 该干啥干啥去!</div>
            <div class="img"></div>
        </div>
    </main>

    <script src="./js/Clock.js"></script>
    <script src="./js/Timer.js"></script>
    <script>
        // 创建获取时间的时钟组件
        let clockComponents = new ClockComponents("#ClockComponents")
        clockComponents.putTime()

        function randomNum(minNum,maxNum){ 
            switch(arguments.length){ 
                case 1: 
                    return parseInt(Math.random()*minNum+1,10); 
                break; 
                case 2: 
                    return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); 
                break; 
                    default: 
                        return 0; 
                    break; 
            } 
        } 

        // 创建计时器 并指定定时器的间隔
        let timer = new Timer(1000)
        // 向计时器添加任务
        timer.addTesk(()=> {
            // 刷新时间
            clockComponents.putTime()
        })
        timer.addTesk(()=> {
            // 日夜循环
            if (clockComponents.getTime().hours >= 19 || clockComponents.getTime().hours <= 5) {
                document.querySelector('main').classList.add('night')
                document.querySelector('#ClockComponents').classList.add('night')
            }else if (clockComponents.getTime().hours >= 5) {
                document.querySelector('main').classList.remove('night')
                document.querySelector('#ClockComponents').classList.remove('night')
            }
        })
        timer.addTesk(()=> {
            // 每一段时间显示不同的消息
            let text = ""
            let time = clockComponents.getTime().hours
            if (time <= 3) {
                text = "熬夜对身体不好哦 但是不管怎样请加油(๑•̀ㅂ•́)و✧"
            }
            if (time >= 4) {
                text = "赶紧去睡觉啊 混蛋(ノ｀Д)ノ"
            }
            if (time >= 7) {
                text = "早上好啊╰(￣ω￣ｏ)"
            }
            if (time >= 12 && time <= 13) {
                text = "中午吃的啥呀o(*￣▽￣*)ブ"
            }
            if (time >= 14 && time <= 17) {
                text = "下午好热哦（；´д｀）ゞ"
            }
            if (time >= 18 && time <= 19) {
                text = "(*￣3￣)╭该吃晚饭了哦"
            }
            if (time >= 20 && time <= 23) {
                text = "晚上好啊ヾ(^▽^*)))"
            }
            if (time >= 23) {
                text = "熬夜对身体不好哦 但是不管怎样请加油(๑•̀ㅂ•́)و✧"
            }
            
            document.querySelector("#message").innerHTML = text
        })
        timer.addTesk(()=> {
            let num1 = randomNum(30, 60)
            let num2 = randomNum(0, 2)
            let imgList = [
                "./img/22222.png",
                "./img/33333.png",
                "./img/11111.png",
            ]
            let reminder = document.querySelector("#reminder")
            let textDom = document.querySelector("#reminder .text")
            let imgDom = document.querySelector("#reminder .img")
            if (num1 == 45) {
                reminder.style.left = "0vw"
                imgDom.style.backgroundImage = "url("+imgList[num2]+")"
                textDom.style.top = "-" + ((10*num2*3)+30) + "px"
            }else {
                setTimeout(() => {
                    reminder.style.left = "-50vw" 
                }, 1000);
            }
        })
        // 运行计时器
        timer.start()
    </script>
</body>
</html>